package ru.futurelink.moneyorganizer.widgets;

import java.util.ArrayList;

import android.content.Context;
import android.util.FloatMath;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MOGraphicHeader extends LinearLayout {
	private ArrayList<TextView>		mCells;

	public MOGraphicHeader(Context context) {
		super(context);

		setOrientation(LinearLayout.HORIZONTAL);
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		setLayoutParams(params);
		
		mCells = new ArrayList<TextView>();
				
		for (int i = 0; i < 10; i++) {
			TextView a = new TextView(context);
			a.setText("header #"+i+":"+i);
			a.setGravity(Gravity.CENTER);
			params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			params.setMargins(1, 0, 0, 1);
			addView(a, params);
			mCells.add(a);
		}
	}

	public void setItemWidth(int itemWidth) {
		float pxItemWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, itemWidth, getResources().getDisplayMetrics());		
		for(int i = 0; i < mCells.size(); i++) {
			mCells.get(i).setWidth((int)FloatMath.ceil(pxItemWidth));
		}
	}
	
	public void setHeight(int height) {
		for(int i = 0; i < mCells.size(); i++) {
			mCells.get(i).setHeight(height);			
		}
	}
	
	public void setBackgroundColor(int color) {
		for(int i = 0; i < mCells.size(); i++) {
			mCells.get(i).setBackgroundColor(color);			
		}		
	}

}
